<?php
//First include the file that has all the functions you need
include_once("tutorialFunctions.php");
?>
<!-- Your main concern is fitting data into HTML -->
<!-- This is an example of what HTML before your data might look like -->
<style>
	table {
		border: solid 1px #000;
		margin: 5px;
	}
	td {
		border: solid 1px #000;
	}
</style>

<h2>Simple Example</h2>
<table>
<?php
/*
	now we begin collecting the data
	i created a variable called "results" that gets array that the function returns
*/
$results = getBasic(); //this function is in the previously included php file
/*
	now the variables "results" holds an array of data. We'll iterate through the data
	and we'll print all the data using HTML elements "<div>"
*/

// $results is the variable that holds the array
// $key is the key of the current array element
// $value is the value of the current array element
foreach($results as $key => $value){
	?>
	<tr>
	<td class="key">Key: <?php echo($key); ?></td>
	<td class="value">Name: <?php echo($value); ?></td>
	</tr>
	<?php
}

?>
</table>

<!-- Okay, now let's try this with a more complex array -->
<!-- Note! Even though this is more complex than the above example, it is still very simple! -->
<!-- All the following code does is -->
<!-- a) search for the values and return them -->
<!-- b) check if it's a success or fail -->
<!-- c) only if its a success, iterate through those values with a foreach -->
<!-- d) draw these values using HTML elements -->
<h2>Slightly Complex Example</h2>

<!-- this should succeed -->
<table>
<?php
$searchString = "keane";
printResultsFromBackEnd($searchString);
?>
</table>

<!-- this should succeed -->
<table>
<?php
$searchString = "charles";
printResultsFromBackEnd($searchString);
?>
</table>

<!-- this should fail -->
<table>
<?php
$searchString = "anthony";
printResultsFromBackEnd($searchString);?>
</table>

<?php
function printResultsFromBackEnd($searchString){
	?>
		<tr>
			<td colspan="2"><?php echo($searchString); ?></td>
		</tr>

	<?php

	$results = getComplex($searchString);
	if($results[0] == "success"){
		foreach($results[1] as $key => $value){
			?>
			<tr>
				<td><?php echo($key); ?></td>
				<td><?php echo($value); ?></td>
			</tr>
			<?php
		}
	} else {
		?><tr><td colspan="2">Fail</td></tr><?php
	}
}
?>